package com.quyeying.service.impl;

import com.quyeying.entity.TblOrderStatusRecordEntity;
import com.quyeying.enums.TblOrderStatusRecordEnum;
import com.quyeying.mapper.TblOrderStatusRecordDao;
import com.quyeying.service.TblOrderStatusRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.quyeying.utils.result.R;
import com.quyeying.utils.result.ReturnPageData;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

/**
* <p>
 * 订单状态记录表 服务实现类
 * </p>
*
* @author skx
* @since 2022-07-19
*/
@Service
public class TblOrderStatusRecordServiceImpl extends ServiceImpl<TblOrderStatusRecordDao, TblOrderStatusRecordEntity> implements TblOrderStatusRecordService {

    @Override
    public R findListByPage(Integer page, Integer pageCount){
        IPage<TblOrderStatusRecordEntity> wherePage = new Page<>(page, pageCount);
        TblOrderStatusRecordEntity where = new TblOrderStatusRecordEntity();
        IPage<TblOrderStatusRecordEntity> iPage = baseMapper.selectPage(wherePage, Wrappers.query(where));
        return R.success(ReturnPageData.fillingData(iPage));
    }

    @Override
    public R add(TblOrderStatusRecordEntity tblOrderStatusRecordEntity){
        baseMapper.insert(tblOrderStatusRecordEntity);
        return R.success();
    }

    @Override
    public R delete(Long id){
        baseMapper.deleteById(id);
        return R.success();
    }

    @Override
    public R updateData(TblOrderStatusRecordEntity tblOrderStatusRecordEntity){
        baseMapper.updateById(tblOrderStatusRecordEntity);
        return R.success();
    }

    @Override
    public R findById(Long id){
        TblOrderStatusRecordEntity tblOrderStatusRecordEntity = baseMapper.selectById(id);
        return R.success(tblOrderStatusRecordEntity);
    }

    @Override
    public void addOrderStatusRecord(Long orderId, Integer statusCode){
        TblOrderStatusRecordEntity orderStatusRecordEntity = new TblOrderStatusRecordEntity();
        orderStatusRecordEntity.setOrderId(orderId);
        orderStatusRecordEntity.setOrderStatus(statusCode);
        baseMapper.insert(orderStatusRecordEntity);
    }
}
